package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleUserMapper;
import com.atguigu.spzx.manager.service.SysRoleUserService;
import com.atguigu.spzx.model.dto.system.AssginRoleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName: SysRoleUserServiceImpl
 * @Package: com.atguigu.spzx.manager.service.impl
 * @Description
 * @Author 孤妤
 * @Date: 2023/12/5 19:06
 */
@Service
@Transactional
public class SysRoleUserServiceImpl implements SysRoleUserService {
    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;
    @Override
    public void doAssign(AssginRoleDto assginRoleDto) {
        // 首先删除该用户的角色重新分配
        sysRoleUserMapper.removeAssign(assginRoleDto.getUserId());
        // 判断角色id是否勾选,勾选执行分配,没有勾选直接返回
        if (assginRoleDto.getRoleIdList().size()>0){
            sysRoleUserMapper.insertAssign(assginRoleDto);
        }
    }
}
